package wjio;

import java.io.File;
import java.util.Scanner;

public class demo13_0527 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要搜索的文件名：");
        String filename = scanner.next();
        System.out.println("请输入要搜索的目录:");
        String rootPath = scanner.next();
        File rootfile = new File(rootPath);
        System.out.println(rootfile.getName());
        if (!rootfile.isDirectory()) {
            System.out.println("路径有误");
            return;
        }
        scanDir(rootfile,filename);

    }

    private static void scanDir(File rootfile, String filename) {
        File[] files = rootfile.listFiles();
        if (files == null) {
            return;
        }
        for (File f : files) {
            //System.out.println("当前遍历到：" + f.getAbsoluteFile());
            if (f.isFile()) {
                if (f.getName().equals(filename)) {
                    System.out.println("找到了");
                    System.out.println("文件的绝对路径为：" + f.getAbsoluteFile());
                    return;
                }
            } else if (f.isDirectory()) {
                scanDir(f,filename);
            } else {

            }
        }
    }
}
